export default {
    state: {
        carts: []
    },
    getters: {
        getCarts: state => state.carts
    },
    mutations: {
        setCarts(state) {
            const user = JSON.parse(localStorage.getItem("bmob"));
            if(user) {
                const query = Bmob.Query("Cart");
                query.equalTo("userId", "==", user.objectId);
                query.find().then(response => {
                    response.total = response.reduce((sum, item) => sum + parseInt(item.totalPrice), 0);
                    response.total += ".00";
                    state.carts = response;
                });
            }else {
                state.carts = [];
            }
            console.log("setCarts ok!");
        }
    },
    actions: {

    }
}